๋ฌธ์ ์ํฉ
<NoProfile size="..." />
์ด๋ ๊ฒ ์ปดํฌ๋ํธ๋ฅผ ํ๋ ๋ง๋ค๊ณ ํฌ๊ธฐ๋ง ๋ฐ๋ก props๋ก ๋๊ฒจ์ฃผ๋ฉด์ ํ์ํ ๋๋ง๋ค ๋ค๋ฅธ ํฌ๊ธฐ์ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค์ด ํ์ฉํ๋ ค๊ณ ํ๋ค.
๊ทธ๋ฐ๋ฐ, 6๋ง ์ ๋๋ก ํฌ๊ธฐ๊ฐ ์กฐ์ ๋๊ณ ๋๋จธ์ง ๋ชจ๋ ์ซ์๋ค์ ๋ถ๋ชจ๊ฐ ๊ฐ์ง flex
๋๋ฌธ์ ๊ฝ ์ฐจ๋ฒ๋ฆฌ๊ฒ ๋๋ค.
์ฝ๋
import NoProfile from "public/no-profile";
export function Chat() {
return (
<div className="flex flex-col w-1/6 items-center">
<div className="flex justify-center">
<NoProfile size="full" />
</div>
<span>username</span>
</div>
);
}
export default function ChatList() {
return (
<div className="bg-gray-200 mt-6 rounded-xl p-4 grid grid-rows-1">
<Chat />
</div>
);
}
///////
export default function NoProfile({ size }: { size: string }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className={`size-${size}`}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.963 0a9 9 0 1 0-11.963 0m11.963 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
/>
</svg>
);
}
์์ธ
ํ ์ผ์๋๊ฐ ์ฌ์ฉํ๋ JIT ์ปดํ์ผ๋ฌ ๋ฐฉ์ ๋๋ฌธ. ํ ์ผ์๋๋ (2.1๋ฒ์ ์ดํ๋ถํฐ) ๋ชจ๋ ๊ฐ๋ฅํ ํด๋์ค๋ค์ ๋ฏธ๋ฆฌ ์์ฑํ๊ณ , ๋น๋์์ ์ฌ์ฉํ์ง ์๋๊ฒ๋ค์ ์ ๊ฑฐํ๋ ๋ฐฉ์์ผ๋ก ์๋ํ๋ค. ๊ทธ๋ฌ๋ ์ง๊ธ์ ๋ฐ๋๋ก ์ฝ๋์ ์ง์ ์์ฑ๋์ด์๋ ํด๋์ค๋ค๋ง ์์ฑํ๋ค.
์ฆ, ๋์ ์ผ๋ก ํด๋์ค๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ size-${size}
์ ์ฌ์ฉํ๋ฉด ๋น๋ํ ๋ ํ
์ผ์๋ ์ปดํ์ผ๋ฌ๊ฐ ์ ํจํ ํด๋์ค๋ช
์ด๋ผ๊ณ ์์๋ณด์ง ๋ชปํด์ ํด๋์ค๋ฅผ ์์ฑํ์ง ์์์ ๋ฐ์ํ๋ ๋ฌธ์ .
ํด๊ฒฐ
tailwind.config.ts
์ ์ธ์ดํ๋ฆฌ์คํธ๋ฅผ ์์ฑํด๋ ๋๋ค๊ณ ํ๋ค.
๊ทธ๋ฌ๋ ๋๋ prop mapping ๋ฐฉ์์ ์ฌ์ฉํ๊ธฐ๋ก ํ๋ค.
function Button({ color, children }) {
const colorVariants = {
blue: "bg-blue-600 hover:bg-blue-500",
red: "bg-red-600 hover:bg-red-500",
};
return (
<button
className={`${colorVariants[color]} ...`}
>
{children}
</button>
);}
ํด๋์ค๋ช ์ ๋ด๊ณ ์๋ ๊ฐ์ฒด๋ฅผ ํ๋ ๋ง๋ค์ด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ. ๊ฐ์ฒด ์์ ์ด๋ฏธ ํ ์ผ์๋ ๋ฌธ๋ฒ์ผ๋ก ์์ฑ๋ ํด๋์ค๋ช ์ด ์์ด์ ์ปดํ์ผ๋ฌ๊ฐ ๋นผ๋์ง ์๊ณ ํด๋์ค๋ฅผ ์์ฑํ๋ค.